import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  // UseGuards,
  // SetMetadata,
} from '@nestjs/common';
import {
  ApiTags,
  ApiOperation,
  ApiBearerAuth,
  ApiParam,
  ApiQuery,
  ApiResponse,
} from '@nestjs/swagger';
import { GuardService } from './guard.service';
import { CreateGuardDto } from './dto/create-guard.dto';
import { UpdateGuardDto } from './dto/update-guard.dto';
// import { RoleGuard } from './role/role.guard';
import { Role, ReqUrl } from './role/role.decorator';
@Controller('guard')
@ApiBearerAuth()
@ApiTags('守卫接口')
// @UseGuards(RoleGuard)
export class GuardController {
  constructor(private readonly guardService: GuardService) {}

  @Post()
  create(@Body() createGuardDto: CreateGuardDto) {
    return this.guardService.create(createGuardDto);
  }

  @Get()
  @Role('admin') //第一个是key 第二个是被判断的是否有该权限
  @ApiOperation({ summary: '获取用户列表', description: '12333' }) //接口描述
  findAll(@ReqUrl('123') url: string) {
    console.log(url);
    return this.guardService.findAll();
  }

  @Get(':id')
  @ApiParam({ name: 'id', description: '用户id', required: true }) //参数描述
  @ApiQuery({ name: 'page', description: '分页信息' }) //查询参数描述
  @ApiResponse({
    status: 200,
    description: '获取用户信息',
    type: CreateGuardDto,
  })
  findOne(@Param('id') id: string) {
    return this.guardService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateGuardDto: UpdateGuardDto) {
    return this.guardService.update(+id, updateGuardDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.guardService.remove(+id);
  }
}
